var cur={
		action:{
			
		},constant:{
			pageNo:1,
			pageSize:15,
		}
}

;$(function() {
	getListPage();
})
 var tale = new $.tale();
function getListPage(){
	var  type = $("#selectType").val();
	$.ajax({
    	url: ctxPath+"/agency/workGuide/getPage",
        type: 'POST',
        data: {pageNo:cur.constant.pageNo,pageSize:cur.constant.pageSize,"type":type},
        success: function(d){
        	 if(d.data!=null){
        		 var html="";
        	$.each(d.data.dataList,function(i,item){
        		html+=toHtml(item);
        	})	
        	$("#list_result").html(html);
        	} 
        getPage(d.data.pages,d.data.total);	 
        }
    });
}

//分页
function getPage(pageCount,totalCount){
	kkpager.total =pageCount ;//总页码
	kkpager.totalRecords = totalCount;//总条数
	kkpager.generPageHtml({
		pno : 0,
		mode : 'click',//默认值是link，可选link或者click
		click : function(n){
			cur.constant.pageNo = n;
			getListPage();
			this.selectPage(n);
		    return false;
		}
	});
}

 function toHtml(data){
	 var date = data.updateTime;
	 if(date==null){
		 date= data.createTime;
	 }
	 var img=ctxPath+'/image/defualt.png';
	 if(data.fileId!=null){
		 img=ctxPath+'/file/showImage/'+data.fileId;
	 }
	 return '<tr>'
		 +'<td>'
	     +'<a href="'+ctxPath+'/agency/workGuide/detail/'+data.id+'" style="cursor: pointer;"><img src="'+img+'" width="50px;">&nbsp;&nbsp;&nbsp;&nbsp;'
	     +'</a></td>'
         +'<td>'
         +data.name
         +'</td>'
         +'<td>'
         +data.typeName
         +'</td>'
         +'<td>'
         +date
         +'</td>'
         +'<td>'
         +'<a  class="btn btn-primary btn-sm waves-effect waves-light m-b-5" href="/agency/workGuide/edit/'+data.id+'"><i class="fa fa-edit"></i>编辑</a>'
         +'<button type="button" class="btn btn-danger btn-sm waves-effect waves-light m-b-5" onclick="del(' + data.id + ')"><i class="fa fa-trash-o"></i> 删除</button>'
         +'<a  class="btn btn-info btn-sm waves-effect waves-light m-b-5" href="/agency/workGuide/detail/'+data.id+'"><i class="fa fa-rocket"></i>详情</a>'
         +'</td>'
         +'</tr>';
 }
 
 
 
 function del(id){
    tale.alertConfirm({
        title:'确定删除吗?',
        then: function () {
            tale.post({
                url : ctxPath+'/agency/workGuide/del',
                data: {id: id},
                success: function (result) {
                    if(result && result.success == true){
                        tale.alertOkAndReload('删除成功');
                    } else {
                        tale.alertError(result.msg || '删除失败');
                    }
                }
            });
        }
    });
 }
 
